package com.yanlin.serviceverificationcode.controller;

import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.internalcommon.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>标题：NumberCodeController</p>
 * <p>功能：</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-04 20:21</p>
 *
 * @author yanlin
 */
@RestController
public class NumberCodeController {

    @GetMapping("/number-code/{size}")
    public ResponseResult numberCode(@PathVariable Integer size){
        //  生产验证码
        double random = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
        int numberCode = (int) random;
        System.out.println("generate src numberCode = " + numberCode);
        // 封装返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(numberCode);
        return ResponseResult.success(response);
    }

    public static void main(String[] args) {

        double random = (Math.random() * 9 + 1) * (Math.pow(10, 5));

        System.out.println("random = " + random);
    }
}